package lanou.a36ke_01.adapters.equityadapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import lanou.a36ke_01.beanlists.equitybean.EquityAllBean;
import lanou.a36ke_01.R;
import lanou.a36ke_01.tools.NetTool;

public class EquityAllAdapter extends BaseAdapter {

    Context mContext;
    EquityAllBean equityAllBean;

    public void setEquityAllBean(EquityAllBean equityAllBean) {
        this.equityAllBean = equityAllBean;
    }

    public EquityAllAdapter(Context mContext) {
        this.mContext = mContext;
    }


    @Override
    public int getCount() {
        return equityAllBean.getData().getData().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.equity_item_adapter, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        NetTool netTool = new NetTool();
        netTool.getImage(equityAllBean.getData().getData().get(position).getCompany_logo(), viewHolder.logo);
        viewHolder.name.setText(equityAllBean.getData().getData().get(position).getCompany_name());
        viewHolder.brief.setText(equityAllBean.getData().getData().get(position).getCompany_brief());
        netTool.getImage(equityAllBean.getData().getData().get(position).getFile_list_img(), viewHolder.lisimg);
        viewHolder.leadName.setText(equityAllBean.getData().getData().get(position).getLead_name());
        viewHolder.adname.setText(equityAllBean.getData().getData().get(position).getCf_advantage().get(0).getAdname());
        viewHolder.adcontent.setText(equityAllBean.getData().getData().get(position).getCf_advantage().get(0).getAdcontent());
        viewHolder.adnameTwo.setText(equityAllBean.getData().getData().get(position).getCf_advantage().get(1).getAdname());
        viewHolder.adcontentTwo.setText(equityAllBean.getData().getData().get(position).getCf_advantage().get(1).getAdcontent());
        viewHolder.desc.setText(equityAllBean.getData().getData().get(position).getFundStatus().getDesc());
        int much = (int) (equityAllBean.getData().getData().get(position).getRate() * 100);
        viewHolder.rate.setText(much + "%");
        if (much < 100) {
            viewHolder.corowFud.setProgress(much);
        } else {
            viewHolder.corowFud.setProgress(100);
        }
        if (much >= 80) {
            viewHolder.btnQk.setText("去看看");
            viewHolder.btnQk.setTextColor(Color.BLACK);
            viewHolder.btnQk.setBackgroundColor(Color.WHITE);
        } else if (much < 80) {
            viewHolder.btnQk.setText("认购");
            viewHolder.btnQk.setBackgroundColor(Color.RED);
        }

        return convertView;
    }

    public class ViewHolder {
        ImageView logo;
        TextView name;
        TextView brief;
        ImageView lisimg;
        TextView leadName;
        TextView adname;
        TextView adcontent;
        TextView adnameTwo;
        TextView adcontentTwo;
        TextView desc;
        TextView rate;
        SeekBar corowFud;
        Button btnQk;


        public ViewHolder(View view) {
            logo = (ImageView) view.findViewById(R.id.equityall_adapter_image_title);
            name = (TextView) view.findViewById(R.id.equity_adapter_text_title);
            brief = (TextView) view.findViewById(R.id.equity_adapter_text_context);
            lisimg = (ImageView) view.findViewById(R.id.equity_adapter_image_poster);
            leadName = (TextView) view.findViewById(R.id.equity_adapter_text_two);
            adname = (TextView) view.findViewById(R.id.equity_adapter_text_three);
            adcontent = (TextView) view.findViewById(R.id.equity_adapter_text_four);
            adnameTwo = (TextView) view.findViewById(R.id.equity_adapter_text_five);
            adcontentTwo = (TextView) view.findViewById(R.id.equity_adapter_text_six);
            desc = (TextView) view.findViewById(R.id.equity_adapter_text_progress);
            rate = (TextView) view.findViewById(R.id.equity_adapter_text_time);
            corowFud = (SeekBar) view.findViewById(R.id.equity_adapter_seekbar);
            btnQk = (Button) view.findViewById(R.id.equity_adapter_button);


        }
    }

}
